package com.controller;

import com.component.ErrorCode;
import com.exception.ExceptionCast;
import com.entity.User;
import com.response.BaseResponse;
import com.response.DataResponse;
import com.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName UserController
 * @Description 用户相关api
 * @Author XiangQian
 * @Date 2022/7/7 9:37
 */
@RestController
@RequestMapping("/User")
@Api(value = "用户接口")
public class UserController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionCast.class);
    @Autowired
    private UserService userService;
    @ApiOperation("用户注册")
    @PostMapping("/new")
    public BaseResponse save(@RequestBody User user) {
        userService.insertUser(user);
        return new BaseResponse(ErrorCode.RegisterSuccess);
    }
    @ApiOperation("用户登陆")
    @PostMapping("/login")
    public DataResponse<String> login(@RequestBody User user) {
        return new DataResponse(ErrorCode.LoginSuccess, userService.selectUserByUserInfo(user));
    }
    @ApiOperation(value = "禁止用户信息")
    @PutMapping("/{username}")
    public BaseResponse prohibit(@RequestBody User user) {
        userService.stopUser(user);
        return new BaseResponse(ErrorCode.ProhibitUserSuccess);
    }
    @ApiOperation(value = "删除用户")
    @PostMapping("/delete")
    public BaseResponse deleteUser(@RequestBody User user) {
        userService.deleteUser(user);
        return new BaseResponse(ErrorCode.DeleteUserSuccess);
    }

}
